package com.woniu.mgr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.mgr.model.Article;
import com.woniu.mgr.dao.ArticleDao;
import com.woniu.mgr.model.Coach;
import com.woniu.mgr.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 文章表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {

    @Resource
    private ArticleDao articleDao;
    @Override
    public IPage<Article> list(Integer page, Integer size) {
        //分页查询
        Page<Article> pages = new Page<>(page, size);
        QueryWrapper<Article> wrapper = new QueryWrapper<>();
        Page<Article> page1 = articleDao.selectPage(pages, wrapper);
        return page1;
    }
    @Override
    public Page<Article> query(String condition, Integer current, Integer size) {
        Page<Article> page = new Page<>(current == null ? 1 : current, size == null ? 4 : size);
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        if (!"".equals(condition) || condition != null) {
            queryWrapper.like("title", condition)
                    .or().eq("poster", condition)
                    .or().like("content", condition);
        }
        Page<Article> articlePage = articleDao.selectPage(page, queryWrapper);
        return articlePage;
    }
}
